package unused;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

import org.jibble.pircbot.IrcException;
import org.jibble.pircbot.NickAlreadyInUseException;




import com.hogofwar.DJbot.BasePlugin;
import com.hogofwar.DJbot.IRCBase;

public class COM_multitest implements BasePlugin {

	public void start(final IRCBase irc, final String[] extra, String channel,
			String sender, String hostname, boolean usename) {
		String start = "";
		if (usename == true) {
			start = sender + ": ";
		}
		 StringBuilder text = new StringBuilder();
		    String NL = System.getProperty("line.separator");
		    Scanner scanner = null;
			try {
				scanner = new Scanner(new FileInputStream("plugins/bin/stillalive"));
			} catch (FileNotFoundException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			if(extra.length == 0 || extra[0].equalsIgnoreCase("2")){
		    try {
		    	boolean first = true;
		    	boolean first2 = true;
		    	SecondIRC second = new SecondIRC("Caroline");
		    	irc.changeNick("Cave");
		      while (scanner.hasNextLine()){
		        if(first){
		        	irc.sendMessage(channel, scanner.nextLine());
		        	
		        	Thread.sleep(2000);
		        	first=false;
		        }else{
		        	second.say(channel, scanner.nextLine());
		        	first=true;
		        	Thread.sleep(2000);
		        }
		        
		      }
		      irc.changeNick("Om");
		        second.quitServer("Song over!");
		    } catch (NickAlreadyInUseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IrcException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
		      scanner.close();
		    }
			}else if(extra[0].equalsIgnoreCase("3")){
				try {
			    	int first = 1;
			    	boolean first2 = true;
			    	SecondIRC second = new SecondIRC("Caroline");
			    	SecondIRC second2 = new SecondIRC("Chell");
			    	irc.changeNick("GLaDOS");
			      while (scanner.hasNextLine()){
			        if(first == 1){
			        	irc.sendMessage(channel, scanner.nextLine());
			        	
			        	Thread.sleep(2000);
			        	first = 2;
			        }
			        if(first == 2){
			        	second.sendMessage(channel, scanner.nextLine());
			        	
			        	Thread.sleep(2000);
			        	first = 3;
			        }
			        if(first == 3){
			        	second2.sendMessage(channel, scanner.nextLine());
			        	
			        	Thread.sleep(2000);
			        	first = 1;
			        }
			        
			      }
			      irc.changeNick("Om");
			        second.quitServer("Song over!");
			    } catch (NickAlreadyInUseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IrcException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				
	}
	finally
			{
		      scanner.close();
		    }
			}
	}
		    
	

	public String help() {
		return "MultiTest - Double Pong!";
		// TODO Auto-generated method stub

	}

	public String version() {
		return "MT version 1";
		// TODO Auto-generated method stub

	}

	@Override
	public String restrict() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Boolean hide() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String aliases() {
		// TODO Auto-generated method stub
		return "mt, multi, test";
	}

}
